package cn.lzd.mvp.base.struct;

import java.lang.reflect.ParameterizedType;

public interface InitialPro <P extends IPresenter> {
    @SuppressWarnings("unchecked")
    default P initPresenter() {
        try {
            ParameterizedType type = (ParameterizedType) getClass().getGenericSuperclass();
            if (type == null) {
                throw new RuntimeException("运行异常，初始化失败: " + getClass().getSimpleName());
            }
            Class<P> classM = (Class<P>) type.getActualTypeArguments()[0];

            return  (P) classM.getConstructors()[0].newInstance(this);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    /**
     * 初始化布局，比如控件显示状态，点击事件等
     */
    default void initView() {

    }
    /**
     * 设置ContentView Layout id
     */
    int getContentViewId();
}
